import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import autoprefixer from 'autoprefixer';
import tailwindcss from 'tailwindcss';
import { ElementPlusResolver, VantResolver } from "unplugin-vue-components/resolvers";
import postcssPresetEnv from 'postcss-preset-env';
import Pages from 'vite-plugin-pages';
import { viteMockServe } from "vite-plugin-mock";


// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    viteMockServe({
      mockPath: 'src/apis/mock',
      logger:true,
      enable:true,
    }),
    Pages({
      dirs: [{ dir: "src/module/pages/", baseRoute: "/" }],
      onRoutesGenerated(routes) {
        routes.forEach(route => {
          route.name=route.name.replace(/-([a-z])/g, (match:string, letter:string) => letter.toUpperCase());
        })
      },
      importMode: "async",
    }),
    AutoImport({
      resolvers: [ElementPlusResolver(),VantResolver()],
      imports: ["vue","vue-router","pinia",],
      dirs: ['src/services/**/*.ts','src/services/apis/**/*.ts'],
      dts: 'src/output/dist/auto-imports.d.ts',
    }),
    Components({
      resolvers: [ElementPlusResolver(),VantResolver()],
      dirs: ["src/module/components/"],
      dts: 'src/output/dist/auto-components.d.ts',
    }),
  ],
  css:{
    postcss:{
      plugins:[autoprefixer(),tailwindcss(),postcssPresetEnv()]
    }
  }
});
